* ssc install xtvar
clear

import delimited "xtvar_ready.csv"

* setup
encode state, gen(state1)
gen date1 = date(date, "YMD")
gen mdate = mofd(date1)
format mdate %tm
xtset state1 mdate, monthly

* unemp rate
clear matrix
xtvar hp_ln_epu_composite hp_unemp_rate, dbsn lags(6) step(60) ssaving("hp_unemp_rate.dta")
clear matrix
xtvar ln_epu_composite unemp_rate, dbsn lags(6) step(60) ssaving("unemp_rate.dta")

* employment
clear matrix
xtvar hp_ln_epu_composite hp_ln_employment, dbsn lags(6) step(60) ssaving("hp_ln_employment.dta")
clear matrix
xtvar ln_epu_composite ln_employment, dbsn lags(6) step(60) ssaving("ln_employment.dta")

* reversed ordering
clear matrix
xtvar hp_unemp_rate hp_ln_epu_composite, dbsn lags(6) step(60) ssaving("hp_unemp_rate_reversed.dta")
clear matrix
xtvar unemp_rate ln_epu_composite, dbsn lags(6) step(60) ssaving("unemp_rate_reversed.dta")

* START HAMILTON FILTER MODELS
drop if missing(hf_ln_epu_composite)

*reversed ordering
clear matrix
xtvar hf_unemp_rate hf_ln_epu_composite, dbsn lags(6) step(60) ssaving("hf_unemp_rate_reversed.dta")

*lag comp
clear matrix
xtvar hf_ln_epu_composite hf_unemp_rate, dbsn lags(12) step(60) ssaving("/hf_unemp_rate_12lag.dta")
clear matrix
xtvar hf_ln_epu_composite hf_unemp_rate, dbsn lags(3) step(60) ssaving("hf_unemp_rate_3lag.dta")

* unemp rate and employment hf filter
clear matrix
xtvar hf_ln_epu_composite hf_unemp_rate, dbsn lags(6) step(60) ssaving("hf_unemp_rate.dta")
clear matrix
xtvar hf_ln_epu_composite hf_ln_employment, dbsn lags(6) step(60) ssaving("hf_ln_employment.dta")